//
//  CellTopView.swift
//  weibo
//
//  Created by yellow on 15/10/20.
//  Copyright © 2015年 yellow. All rights reserved.
//

import UIKit



class CellTopView: UIView {
    
    var viewModel:StatusDetailViewModel? {
        didSet{
            //当接收viewModel时，就对控件进行数据绑定
            iconView.sd_setImageWithURL(viewModel?.iconViewURL)
            nameLable.text = viewModel?.status.user?.screen_name
            memberIconView.image = viewModel?.memberIconImage
            vipIconView.image = viewModel?.vipIconImage
        }
    }
    
    ///懒加载控件
    
    //分隔线
    private lazy var sepView:UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.lightGrayColor()
        return view
    }()
    ///微博头像
    private lazy var iconView:UIImageView = UIImageView(imageName: "avatar_default_big")
    
    ///微博名
    private lazy var nameLable:UILabel = UILabel(title: "微博名称", color: UIColor.darkGrayColor(), fontSize: 12)
    
    /// 微博会员图标
    private lazy var memberIconView:UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    
    /// 认证图标
    private lazy var vipIconView:UIImageView = UIImageView(imageName: "avatar_vip")
    
    /// 推送时间
    private lazy var timeLabel:UILabel = UILabel(title: "刚刚", color: UIColor.darkGrayColor(), fontSize: 12)
    
    /// 发布微博来源
    private lazy var sourceLabel:UILabel = UILabel(title: "来自:iPhone6S", color: UIColor.darkGrayColor(), fontSize: 12)
    
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


extension CellTopView{

    
    func setUI(){
        
        addSubview(sepView)
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        
        
        //自动布局
        
        sepView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.height.equalTo(10)
        }
        
        //头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(sepView.snp_left).offset(widgetMargin)
            make.top.equalTo(sepView.snp_top).offset(widgetMargin)
            make.height.equalTo(statusIconWidth)
            make.width.equalTo(statusIconWidth)
        }
        
        //昵称
        nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.iconView.snp_top)
            make.left.equalTo(self.iconView.snp_right).offset(widgetMargin)
        }
        
        //微博会员
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.nameLable.snp_top)
            make.left.equalTo(self.nameLable.snp_right).offset(widgetMargin)
        }
        
        //微博认证图标 位于头像的右下角
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.iconView.snp_right)
            make.centerY.equalTo(self.iconView.snp_bottom)
        }
        
        //推送时间
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.iconView.snp_right).offset(widgetMargin)
            make.bottom.equalTo(self.iconView.snp_bottom)
        }
        
        //来源标签
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.timeLabel.snp_right).offset(widgetMargin)
            make.bottom.equalTo(self.timeLabel.snp_bottom)
        }
    }
}


